package cn.tedu.micro.demo.client.delay;

import cn.tedu.micro.demo.client.RabbitChannelManager;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConfirmListener;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

/**
 * 测试消息生产发送
 */
@Slf4j
public class DelayProducer {
    @Test
    public void sendDelay() throws IOException {
        Channel channel = RabbitChannelManager.newChannel();
        //延迟消息 除了在队列中设置x-message-ttl 消息也可以设置超时时间(延迟时间)
        //1.消息体
        byte[] body="hello i am delay msg".getBytes(StandardCharsets.UTF_8);
        //2.消息属性
        AMQP.BasicProperties properties=new AMQP.BasicProperties()
                .builder()
                .deliveryMode(2)//持久化
                .expiration("60000")//毫秒 10秒钟
                .build();
        channel.basicPublish("trans_ex","",properties,body);
        log.info("发送成功");
    }
}
